'''
    Code Name: Python Pong 3D
    
    Module: PyPong.Paddle
    Filename:  __init__.py
    
    Developed by: Juan C. Montes
    
    Created on 26/03/2009
'''


# Referencias de OGRE
import ogre.renderer.OGRE as ogre


''' Clase principal para controlar las barras '''
class Paddle:    
    
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Function: Constructor
    '''
    def __init__(self, scenemanager, paddlename, posX):
        # Definimos los objetos        
        self.scenemanager = ogre.SceneManager
        self.node = ogre.SceneNode
        
        # Guardamos la escena        
        self.scenemanager = scenemanager
        
        # Guardamos el nombre
        self.name = paddlename
        
        # Guardamos la coordenada X
        self.posX = posX


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Function: addToScene
    Descript: Situa la barra en la escena
    ''' 
    def addToScene(self):   
        # Creamos la barra
        ent = self.scenemanager.createEntity(self.name, "cube.mesh")
        ent.setMaterialName(self.name)
        self.node = self.scenemanager.getRootSceneNode().createChildSceneNode(
                    self.name)
        self.node.attachObject(ent)
        self.node.setScale(0.02, 0.30, 0.10)
        self.node.setPosition(self.posX, 0, 0)
    

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Function: movePaddle
    Descript: Movemos la barra
    ''' 
    def movePaddle(self, direction):   
        self.node.translate(direction)
        
        # Ajustamos los limites
        if self.node.getPosition().y > 52.5:
            self.node.setPosition(self.posX, 52.5, 0)
        elif self.node.getPosition().y < -52.5:
            self.node.setPosition(self.posX, -52.5, 0)
        
        
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Function: getPosition
    Descript: Devuelve la posicion de la barra
    ''' 
    def getPosition(self):        
        return self.node.getPosition()   
        